package trees;
/**
 * @author hh
 * 
 */
public class Node {

	private Integer value;
	private Node left, right;

	public Node() {
		value = null;
		left = null;
		right = null;
	}

	public Node(Integer value) {
		setValue(value);
		left = right = null;
	}

	public void setValue(Integer value) {
		this.value=value;
	}

	public Integer getValue() {
		return value;
	}

	public void setLeftNode(Node node) {
		left=node;
	}

	public Node getLeftNode() {
		return left;
	}

	public void setRightNode(Node node) {
		right=node;
	}

	public Node getRightNode() {
		return right;
	}

	
    public boolean remove(int value, Node parent) {

        if (value < this.value) {

              if (left != null)

                    return left.remove(value, this);

              else

                    return false;

        } else if (value > this.value) {

              if (right != null)

                    return right.remove(value, this);

              else

                    return false;

        } else {

              if (left != null && right != null) {

                    this.value = right.minValue();

                    right.remove(this.value, this);

              } else if (parent.left == this) {

                    parent.left = (left != null) ? left : right;

              } else if (parent.right == this) {

                    parent.right = (left != null) ? left : right;

              }

              return true;

        }

  }
    
    public int minValue() {

        if (left == null)

              return value;

        else

              return left.minValue();

  }
	
	
}
